<?php
// $Id: heartbeatstream.inc,v 1.1.2.2 2009/11/15 14:41:53 stalski Exp $

/**
 * Class HeartbeatStream
 *
 * Changeable object with configurations for an activity stream
 */
class HeartbeatStream {

  // Class name actualy used
  public $name = '';

  // Human readable name
  public $title = '';

  // The actor
  public $uid = 0;

  // The relations of the user <uid>
  public $user_relations = array();

  // The module the query builder is located
  public $module = '';

  // Stream access
  public $access = -1;

  // The language for the current stream display
  public $language = 'en';

  // Timestamp to offset the query
  public $offset_sql = 0;

  // Total allowed
  public $limit_sql = 0;

  // First part of the query that is unchangeable
  public $sql_start = '';

  // Last part to finish the sql as heartbeat intends
  public $sql_end = '';

  // Boolean to indicate if it is a page display
  public $pager = FALSE;

  // Boolean to indicate the usage of heartbeat filters
  public $display_filters = FALSE;

  // The filters set for this stream
  public $filters = array();

  // Boolean to indicate if filters have radio or checkbox functionality
  public $filters_cumul = FALSE;

  // Denied message templates
  public $messages_denied = array();

  // Maximum number of items in the block display
  public $block_items_max = 25;

  // Number to indicate how a block-pager should be shown
  public $block_show_pager = 0;

  // Maximum number of items in the page display
  public $page_items_max = 50;

  // Boolean to indicate of a page-pager should be shown
  public $page_show_pager = 0;

  // Boolean to indicate if the pager is ajax-driven
  public $page_pager_ajax = 0;

  // Poll for newer messages
  public $poll_messages = 0;

  // The latest found uaid
  public $latest_uaid = 0;

  /**
   * Constructor to load the type variable
   */
  public function __construct($type) {

    $this->name = strtolower($type['class']);
    $this->title = $type['name'];
    $this->module = $type['module'];
    $this->access = $type['access'];

    if (isset($type['display_filters'])) {
      $this->display_filters = $type['display_filters'];
      $this->filters = $type['filters'];
      $this->filters_cumul = $type['filters_cumul'];
    }

    if (isset($type['messages_denied'])) {
      $this->messages_denied = $type['messages_denied'];
    }

    if (isset($type['poll_messages'])) {
      $this->poll_messages = $type['poll_messages'];
    }

    if (isset($type['settings'])) {
      $this->block_items_max = $type['settings']['block_items_max'];
      $this->block_show_pager = $type['settings']['block_show_pager'];
      $this->page_items_max = $type['settings']['page_items_max'];
      $this->page_show_pager = $type['settings']['page_show_pager'];
      $this->page_pager_ajax = $type['settings']['page_pager_ajax'];
    }
  }

  /**
   * Set the maximum number of items to fetch
   */
  public function setItemsMax($page) {

    if ($page) {
      $this->limit_sql = $this->page_items_max;
    }
    else {
      $this->limit_sql = $this->block_items_max;
    }
  }
}